package com.kiven.thread;

import java.util.Random;

public class ThreadLocalShareData {
	public static ThreadLocal<Integer> threadLocal = new ThreadLocal<Integer>();
	public static void main(String[] args) {
		for (int i=0; i<2; i++) {
			new Thread(new Runnable() {
				@Override
				public void run() {
					int data = new Random().nextInt();
					threadLocal.set(data);
					System.out.println("this is a" 
							+ Thread.currentThread().getName() 
							+ ":" + data);
					
					new A().getA();
					new B().getB();
				}
			}).start();
		}
	}

	static class A {
		public void getA() {
			System.out.println("this is a " 
					+ Thread.currentThread().getName() + " : " 
					+ threadLocal.get());
		}
	}
	
	static class B {
		public void getB() {
			System.out.println("this is B " 
					+ Thread.currentThread().getName() + " : " 
					+ threadLocal.get());
		}
	}

}